home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d3
/
rettig.arc
/
TRSOURCE.EXE
/
_TR_FILE.ASM
< prev
next >
Wrap
Assembly Source File
|
1990-10-22
|
10KB
|
354 lines
; _TR_FILE.ASM
;
; by Leonard Zerman, Ralph Davis
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
PUBLIC __TR_OPEN, __TR_CREAT, __TR_READ
PUBLIC __TR_WRITE, __TR_LSEEK, __TR_CLOSE
PUBLIC __TR_RENAME, __TR_UNLINK, __TR_TELL
;***************************************************************
;
; This file contains TR-LIB file handling routines
; designed to be compatible with C's low level
; file handling functions.
;
; Functions included (and their equivalent C function):
;
; __TR_OPEN open(filename, mode);
; __TR_CREAT creat(filename, file_attribute);
; __TR_READ read(file_descriptor, destination, length);
; __TR_WRITE write(file_descriptor, source, length);
; __TR_CLOSE close(file_descriptor);
; __TR_LSEEK lseek(file_descriptor, offset, seek_mode);
; __TR_RENAME rename(old_filename,new_filename);
; __TR_UNLINK unlink(filename);
;
; Also included (with no low-level C equivalent):
;
; __TR_TELL corresponds to ftell(file_pointer);
; /* uses file_descriptor instead */
;
;****************************************************************
;****************************************************************
_TR_FILE_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TR_FILE_TEXT
;-------------------------------------------------
; file_descriptor = __tr_open(filename, mode)
;
; int file_descriptor;
; char *filename;
; int mode;
;
; Returns: DOS file handle if successful, -1 if not.
;
;----------
__TR_OPEN PROC FAR
PUSH BP
MOV BP,SP
PUSH BX
PUSH DX
PUSH DS
LDS DX,[BP+6] ; Get filename address
MOV AX,[BP+10] ; Get open mode
MOV AH,3DH
INT 21H
JNC _TR_OPEN_EXIT ; File descriptor is in AX
XOR AX,AX ; Return -1 if error
DEC AX
_TR_OPEN_EXIT:
POP DS
POP DX
POP BX
POP BP
RET
__TR_OPEN ENDP
;------------------------------------------------
;
; file_descriptor = __tr_creat(filename, file_attribute)
;
; int file_descriptor;
; char *filename;
; int file_attribute;
;
; Returns: DOS file handle if successful, -1 if not.
;
; File attributes are defined in TRLIB.H as follows:
;
; #define FL_NORMAL 0
; #define FL_RDONLY 1
; #define FL_HIDDEN 2
; #define FL_SYSTEM 4
; #define FL_ARCHIVE 0x20
;
; NOTE: This syntax differs slightly from C syntax.
; C specifies that the second argument is the privilege
; mode of the file. DOS function 3CH, which
; this function uses, expects the second argument
; to be the file attribute (read-only, system, hidden,
; normal, etc.).
;
;----------------
__TR_CREAT PROC FAR
PUSH BP
MOV BP,SP
PUSH BX
PUSH DX
PUSH DS
LDS DX,[BP+6] ; Get filename address
MOV CX,[BP+10] ; Get file attribute
MOV AH,3CH
INT 21H
JNC _TR_CREAT_EXIT ; AX contains file descriptor
XOR AX,AX
DEC AX ; return -1 if error
_TR_CREAT_EXIT:
POP DS
POP DX
POP BX
POP BP
RET
__TR_CREAT ENDP
;------------------------------------------------
;
; status = _tr_read(file_descriptor, destination, length);
;
; int status;
; int file_descriptor;
; char *destination;
; int length;
;
; Returns: number of bytes read if successful, -1 if not.
;
;--------------
__TR_READ PROC FAR
PUSH BP
MOV BP,SP
PUSH BX
PUSH CX
PUSH DX
PUSH DS
MOV BX,[BP+6] ; get file descriptor
LDS DX,[BP+8] ; get address of buffer
MOV CX,[BP+12] ; get number of bytes to read
MOV AH,3FH
INT 21H
JNC _TR_READ_EXIT ; AX contains number of bytes read
XOR AX,AX ; Return -1 for error
DEC AX
_TR_READ_EXIT:
POP DS
POP DX
POP CX
POP BX
POP BP
RET
__TR_READ ENDP
;------------------------------------------------------
;
; status = __tr_write(file_descriptor, source, length);
;
; int status;
; int file_descriptor;
; char *source;
; int length;
;
; Returns: number of bytes written, -1 if error.
;
;-----------
__TR_WRITE PROC FAR
PUSH BP
MOV BP,SP
PUSH BX
PUSH CX
PUSH DX
PUSH DS
MOV BX,[BP+6] ; get file descriptor
LDS DX,[BP+8] ; get address of buffer
MOV CX,[BP+12] ; get number of bytes to write
MOV AH,40H
INT 21H
JNC _TR_WRITE_EXIT ; AX contains number of bytes written
XOR AX,AX ; return -1 for error
DEC AX
_TR_WRITE_EXIT:
POP DS
POP DX
POP CX
POP BX
POP BP
RET
__TR_WRITE ENDP
;------------------------------------------------------
;
; status = _tr_close(file_descriptor);
;
; int status;
; int file_descriptor;
;
; Returns: 0 if successful, -1 if not.
;
;------------
__TR_CLOSE PROC FAR
PUSH BP
MOV BP,SP
PUSH BX
MOV BX,[BP+6] ; get file descriptor
MOV AH,3EH
INT 21H
JNC _TR_CLOSE_GOOD
XOR AX,AX
DEC AX
JMP SHORT _TR_CLOSE_EXIT
_TR_CLOSE_GOOD:
XOR AX,AX ; return 0 if successful
_TR_CLOSE_EXIT:
POP BX
POP BP
RET
__TR_CLOSE ENDP
;---------------------------------------------
;
; position = _tr_lseek(file_descriptor, offset, seek_mode);
;
; long position;
; int file_descriptor;
; long offset;
; int seek_mode;
;
; Returns: New file position if successful, -1L if not.
;
;----------
__TR_LSEEK PROC FAR
PUSH BP
MOV BP,SP
PUSH CX
PUSH DS
PUSH SI
MOV BX,[BP+6] ; get file handle
MOV DX,[BP+8] ; get low word of seek offset
MOV CX,[BP+10] ; get high word of seek offset
MOV AL,[BP+12] ; get offset mode
MOV AH,42H
INT 21H
JNC _TR_LSEEK_GOOD ; DX:AX contains new file position
MOV DX,0FFFFH ; return -1L for error
MOV AX,0FFFFH
JMP SHORT _TR_LSEEK_EXIT
_TR_LSEEK_GOOD:
_TR_LSEEK_EXIT:
POP SI
POP DS
POP CX
POP BP
RET
__TR_LSEEK ENDP
;------------------------------------------------------
;
; position = _tr_tell(file_descriptor);
;
; long position;
; int file_descriptor;
;
; Returns: Current file position if successful, -1L if not.
;
;------------
__TR_TELL PROC FAR
PUSH BP
MOV BP,SP
PUSH CX
PUSH DS
PUSH SI
MOV BX,[BP+6] ; get file handle
MOV AL,1 ; seek from current location
XOR DX,DX ; seek 0 bytes
XOR CX,CX
MOV AH,42H
INT 21H
JNC _TR_TELL_GOOD ; DX:AX contains new file position
MOV DX,0FFFFH ; return -1L for error
MOV AX,0FFFFH
JMP SHORT _TR_TELL_EXIT
_TR_TELL_GOOD:
_TR_TELL_EXIT:
POP SI
POP DS
POP CX
POP BP
RET
__TR_TELL ENDP
;------------------------------------------------------
;
; error = _tr_rename(old_filename,new_filename);
;
; int error;
; char *old_filename;
; char *new_filename;
;
; Returns: 0 if successful, -1 if not
;
;-------------
__TR_RENAME PROC FAR
PUSH BP
MOV BP,SP
PUSH DS
PUSH ES
PUSH DX
PUSH DI
LDS DX,[BP+6] ; get address of old filename
LES DI,[BP+10] ; get address of new filename
MOV AH,56H
INT 21H
JNC _TR_REN_GOOD
XOR AX,AX ; return -1 if error
DEC AX
JMP SHORT _TR_REN_EXIT
_TR_REN_GOOD:
XOR AX,AX ; return 0 for successful execution
_TR_REN_EXIT:
POP DI
POP DX
POP ES
POP DS
POP BP
RET
__TR_RENAME ENDP
;-------------------------------------------------------
;
; error = _tr_unlink(filename);
;
; int error;
; char *filename;
;
; Returns: 0 if successful, -1 if not.
;
;------------
__TR_UNLINK PROC FAR
PUSH BP
MOV BP,SP
PUSH DS
PUSH DX
LDS DX,[BP+6] ; get filename
MOV AH,41H
INT 21H
JNC _TR_UNLINK_GOOD
XOR AX,AX ; return -1 for error
DEC AX
JMP SHORT _TR_UNLINK_EXIT
_TR_UNLINK_GOOD:
XOR AX,AX
_TR_UNLINK_EXIT:
POP DX
POP DS
POP BP
RET
__TR_UNLINK ENDP
;--------------------------------------------------------
_TR_FILE_TEXT ENDS
;******************************************************
END